import request from '@/utils/request'
import { setToken } from '@/utils/storage'
import { LOGIN } from '../constants'
/**
 * 登陆发送请求
 * @param {*} user
 * @returns
 */
export const login = (user) => {
  return async (dispatch) => {
    const res = await request({
      method: 'POST',
      url: '/authorizations',
      data: user,
    })
    setToken(res.data.data.token)
    dispatch({
      type: LOGIN,
      token: res.data.data.token,
    })
  }
}
